package com.example.demo.result;

import com.example.demo.exception.BusinessException;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author wumin
 * @version 1.0
 * @Description: TODO
 * @date 2021/4/7 15:12
 */

@Setter
@Getter
@NoArgsConstructor
public class ResponseResult<T> implements Serializable {

    // http 状态码
    private int code;

    // 返回信息
    private String msg;

    // 返回的数据
    private T data;

    public ResponseResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResponseResult<T> result(int code, String msg, T data) {
        return new ResponseResult<T>(code, msg, data);
    }

    public static <T> ResponseResult<T> success() {
        return new ResponseResult<T>(200, "SUCCESS", null);
    }

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<T>(200, "SUCCESS", data);
    }




    public static <T> ResponseResult<T> error(String msg) {
        return new ResponseResult<T>(500, msg, null);
    }

    public static <T> ResponseResult<T> error(int code, String msg) {
        return new ResponseResult<T>(code, msg, null);
    }

}
